import defaultJson from "./01-default.json";
import darkJson from "./02-dark.json";
import yuequeJson from "./03-yuque.json";

type Theme = "默认" | "暗黑" | "语雀";

const themeToJsonObjMap = new Map<Theme, any>();
themeToJsonObjMap.set("默认", defaultJson);
themeToJsonObjMap.set("暗黑", darkJson);
themeToJsonObjMap.set("语雀", yuequeJson);

function cleanThemeObject(jsonObj: any) {
  if (!jsonObj) {
    throw new Error("主题对应json不存在");
  }
  let newObj: any = {};
  for (const key in jsonObj) {
    if (
      Object.prototype.hasOwnProperty.call(jsonObj, key) &&
      !key.startsWith("$")
    ) {
      newObj[key] = jsonObj[key];
    }
  }
  return newObj;
}

function getThemeByJson(theme: Theme) {
  return cleanThemeObject(themeToJsonObjMap.get(theme));
}

export { getThemeByJson };
export type { Theme };
